﻿namespace NFox.Pycad.Core.Modules
{

    public class io
    {

        private dynamic _console;
        private dynamic _read;
        private dynamic _write;

        public void redirect(dynamic console)
        {
            _console = console;
        }

        public void setdefault(dynamic read, dynamic write)
        {
            _read = read;
            _write = write;
        }

        public string read()
        {
            if (_console != null)
                return _console.read();
            else if (_read != null)
                return _read();
            else
                return "";
        }

        public string readline()
        {
            if (_console != null)
                return _console.read();
            else if (_read != null)
                return _read();
            else
                return "";

        }

        public void write(string s)
        {
            if (_console != null)
                _console.write(s);
            else if (_write != null)
                _write(s);
        }

        public void writeline(string s)
        {
            if (_console != null)
                _console.write(s);
            else if (_write != null)
                _write(s);
        }

        public bool softspace { get; set; }

        public dynamic console { get { return _console; } }

    }

}
